package com.luboyan.CBillbill.service.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luboyan.CBillbill.mapper.user.UserCoinMapper;
import com.luboyan.CBillbill.dao.user.UserCoin;
import com.luboyan.CBillbill.service.user.UserCoinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserCoinServiceImpl implements UserCoinService {

    @Autowired
    private UserCoinMapper userCoinMapper;

    /**
     * 通过userId查询用户硬币
     */
    @Override
    public UserCoin getUserCoinByUserId(Long userId) {
        QueryWrapper<UserCoin> userCoinQueryWrapper = new QueryWrapper<>();
        userCoinQueryWrapper.eq("userId", userId);
        return userCoinMapper.selectOne(userCoinQueryWrapper);
    }

    /**
     * 更新用户硬币数
     */
    @Override
    public void updateUserCoins(UserCoin userCoinAmount, Long userId) {
        QueryWrapper<UserCoin> userCoinQueryWrapper = new QueryWrapper<>();
        userCoinQueryWrapper.eq("userId", userId);
        userCoinMapper.update(userCoinAmount, userCoinQueryWrapper);
    }
}
